﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleGameData.Animations;
using Microsoft.Xna.Framework.Content;

namespace SimpleGameData.GameObjects
{
    public class AnimatedSpriteData : GameObjectData
    {
        #region Fields

        // Dictionary of animations using a enum AnimationKey to identify animations
        private Dictionary<AnimationKey, Animation> animations;

        #endregion

        #region Properties

        /// <summary>
        /// Dictionary of animations using a enum AnimationKey to identify animations.
        /// Use to add new animations to this animated sprite.
        /// </summary>
        public Dictionary<AnimationKey, Animation> Animations
        {
            get { return animations; }
            set { animations = value; }
        }

        #endregion
                
        #region Constructor

        public AnimatedSpriteData() { }

        #endregion
    }

    #region ContentTypeReader Class

    public class AnimatedSpriteDataReader : ContentTypeReader<AnimatedSpriteData>
    {
        protected override AnimatedSpriteData Read(ContentReader input,
            AnimatedSpriteData existingInstance)
        {
            AnimatedSpriteData animatedSpriteData = existingInstance;

            if (animatedSpriteData == null)
            {
                animatedSpriteData = new AnimatedSpriteData();
            }

            input.ReadRawObject<GameObjectData>(animatedSpriteData as GameObjectData);

            animatedSpriteData.Animations = input.ReadObject<Dictionary<AnimationKey, Animation>>();

            return animatedSpriteData;
        }
    }
    #endregion
}
